package com.situ.study;

import java.util.ArrayList;
import java.util.Scanner;

import org.junit.Test;

import com.situ.study.entity.User;

public class Client {
	public static void main(String[] args) {
		User user = new User();
		user.setId(1);
		user.setName("zhangsan");
		user.setAge(120);
		user.setGender("男");

		int id = user.getId();
		String name = user.getName();// Alt + Shift + L
		int age = user.getAge();
		String gender = user.getGender();

		System.out.println(id);
		System.out.println(name);
		System.out.println(age);
		System.out.println(gender);
	}

	@Test
	public void test() {
		User user = new User(1, "张三", 23, "男");
		System.out.println(user.toString());
		System.out.println(user);

	}

	@Test
	public void test1() {
		// while for
		// for (;;) {}
		// User[] array = new User[3];
		// ArrayList LinkedList 冒泡排序
		ArrayList<User> list = new ArrayList<User>();
		Scanner scanner = new Scanner(System.in);
		while (true) {
			System.out.println("请输入id：");
			int id = scanner.nextInt();
			System.out.println("请输入用户名：");
			String name = scanner.next();
			System.out.println("请输入年龄：");
			int age = scanner.nextInt();
			System.out.println("请输入性别：");
			String gender = scanner.next();

			User user = new User(id, name, age, gender);
			list.add(user);

			System.out.println("您是否要退出？-1退出");
			int quit = scanner.nextInt();
			if (quit == -1) {
				// break 只能退出离他最近的一层循环
				break;
			}
		}

//		for (int i = 0; i < list.size(); i++) {
//			User user = list.get(i);
//			System.out.println(user);
//		}

		// foreach
		for (User user : list) {
			System.out.println(user);
		}

		while (true) {
			System.out.println("---------------------");
			System.out.println("按照id来搜索：1");
			System.out.println("按照name来搜索：2");
			System.out.println("按照age来搜索：3");
			System.out.println("按照gender来搜索：4");
			System.out.println("退出：-1");
			System.out.println("---------------------");
			int type = scanner.nextInt();
			// 退出类，或者非法的操作一般放在前面，直接退出
			if (type == -1) {
				break;
			}

			switch (type) {
			case 1:// 按照id来搜索：1

				break;
			case 2:// 按照name来搜索
				System.out.println("请输入搜索的名字");
				String searchName = scanner.next();
				boolean isSearchByNameFound = false;
				for (User user : list) {
					if (searchName.equals(user.getName())) {
						System.out.println(user);
						isSearchByNameFound = true;
						break;
					}
				}
				if (isSearchByNameFound == false) {
					System.out.println("没有该用户的名字");
				}
				break;
			case 4:// 按照gender来搜索：4
				boolean isSearchByGenderFound = false;
				break;

			default:
				break;
			}

		}

	}

}
